import  requests
from  bs4 import BeautifulSoup
import  os
import lxml

dirName = 'img'
if not os.path.exists(dirName):
    os.mkdir(dirName)
#地址
url='http://sc.chinaz.com/tupian/meinvtupian.html'
headers={
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
}
response=requests.get(url=url,headers=headers)
response.encoding='utf-8'
soup=BeautifulSoup(response.text,'html.parser')
print(
soup.select('#container img') [0]['src2'])

for i in soup.select('#container img') :
    src=i['src2']
    path=os.path.join(dirName,i['alt']+'.jpg')
    with open(path,'wb') as p:
        p.write( requests.get(src,headers).content)
    print(i['alt'],'爬取完毕')
    break

